package com.kuang.demo.controller;

import com.kuang.demo.bean.BaseRespVo;
import com.kuang.demo.bo.gh.CreateIssueBO;
import com.kuang.demo.bo.gh.UpdateIssueBO;
import com.kuang.demo.service.IssueService;
import com.kuang.demo.vo.CreateIssueVO;
import com.kuang.demo.vo.QueryIssueVO;
import com.kuang.demo.pojo.IssuePOJO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 郭浩 on 2020/11/3 8:56
 */
@RestController
@RequestMapping("admin/issue")
public class IssueController {
    @Autowired
    IssueService issueService;

    //GET http://182.92.235.201:8083/admin/issue/list?page=1&limit=20&question=%E6%B5%8B%E8%AF%95&sort=add_time&order=desc HTTP/1.1
    @GetMapping("list")
    public BaseRespVo issueList(Integer page,Integer limit,String question,String sort,String order){
        QueryIssueVO queryIssueVO = new QueryIssueVO();
        Map<String, Object> issueInfo = issueService.queryIssueList(page,limit,question,sort,order);
        queryIssueVO.setItems((List<QueryIssueVO.ItemsBean>) issueInfo.get("issueList"));
        queryIssueVO.setTotal((Integer) issueInfo.get("total"));
        return BaseRespVo.ok(queryIssueVO);
    }

    @PostMapping("update")
    public BaseRespVo updateIssue(@RequestBody UpdateIssueBO updateIssueBO){
        IssuePOJO issuePOJO = issueService.updateIssue(updateIssueBO);
        return BaseRespVo.ok(issuePOJO);
    }

    @PostMapping("delete")
    public BaseRespVo deleteIssue(@RequestBody IssuePOJO issuePOJO){
        issueService.deleteIssue(issuePOJO);
        return BaseRespVo.ok();
    }

    @PostMapping("create")
    public BaseRespVo createIssue(@RequestBody CreateIssueBO createIssueBO){
        CreateIssueVO createIssueVO = issueService.createIssue(createIssueBO);
        return BaseRespVo.ok(createIssueVO);
    }
}
